unit ASLdatamodule;

{$mode objfpc}{$H+}

//========================================================================================
//
// Unit : ApplicationDataModule.pas
//
// Description :
//
// Called By : Init : Initialize
//
// Calls : ApplicationSettings : ASLDataPath
//
// Ver. : 1.0.0
//
// Date : 7 Nov 2016
//
//========================================================================================

interface

uses
  Classes, SysUtils, sqlite3conn, sqldb, FileUtil, Dialogs,
  // Appcation units
  ApplicationSettings;

type

  { TdmASLData }

  TdmASLData = class(TDataModule)
    SQLite3ConnectionASLDB: TSQLite3Connection;
    SQLTransactionASLDB: TSQLTransaction;
  private
    { private declarations }
  public
    { public declarations }
    function ConnectASLDB : boolean;
  published
    { published declarations }
  end;// TdmASLData

var
  dmASLData: TdmASLData;


implementation

{$R *.lfm}

const
  cstrASLDBName = 'ASLDB.sl3';

var
  vstrASLDBName : string;

//========================================================================================
//          SUPPORT ROUTINES
//========================================================================================

//========================================================================================
//          PRIVATE ROUTINES
//========================================================================================

//========================================================================================
//          PUBLIC ROUTINES
//========================================================================================
function TdmASLData.ConnectASLDB : boolean;
begin

  // Form the full DB Path each time the DB is connected to ensure that any changes
  // made during this instance are actioned.
  vstrASLDBName := (frmSettings.ASLDataPath + '\' + cstrASLDBName);
//  vstrASLDBName := (frmSettings.ASLDataPath + '\' + 'ASD');

  // Make sure the Database exists.
  if not Fileexists(vstrASLDBName) then
  begin
    showmessage('Unable to locate the ASL Database.');
    result := False;
    Exit;
  end;// if not Fileexists

  // Now connect the controls
  SQLite3ConnectionASLDB.DatabaseName := vstrASLDBName;
  SQLite3ConnectionASLDB.Transaction := SQLTransactionASLDB;
  SQLTransactionASLDB.DataBase := SQLite3ConnectionASLDB;

  SQLite3ConnectionASLDB.Open;

  if not SQLite3ConnectionASLDB.Connected then
  begin
    showmessage('Unable to connect to the ASL Database.');
    showmessage('Unable to locate the ASL Database.');
    Result := False;
    Exit;
  end;// if not SQLite3ConnectionASLDB.Connected

  Result := True;

end;// function TdmASLData.ConnectASLDB

//========================================================================================
//          PUBLISHED ROUTINES
//========================================================================================

//========================================================================================
//          PROPERTY ROUTINES
//========================================================================================

//========================================================================================
//          MENU ROUTINES
//========================================================================================

//========== POPUP MENUS ===================================================================

//========================================================================================
//          TOOLBAR ROUTINES
//========================================================================================

//========================================================================================
//           STATUSBAR ROUTINES
//========================================================================================

//========================================================================================
//          FILE ROUTINES
//========================================================================================

//========================================================================================
//          COMMAND BUTTON ROUTINES
//========================================================================================

//========================================================================================
//          CONTROL ROUTINES
//========================================================================================

//========================================================================================
//          DATABASE ROUTINES
//========================================================================================

//========================================================================================

//========================================================================================
//          FORM ROUTINES
//========================================================================================

//========================================================================================
end.// ApplicationDataModule

